<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <title>{$Think.config.site.title} - 商户管理</title>
    <meta name="keywords" content="{$Think.config.site.keywords}">
    <meta name="description" content="{$Think.config.site.description}">
    <link href="{$Think.config.site.resource_url}css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/animate.min.css" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/plugins/chosen/chosen.css" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/style.min.css?v=4.0.0" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/fileinput.min.css" media="all" rel="stylesheet" type="text/css" />

    <title>传递事件参数</title>
    <style type="text/css">
        * {
            margin: 0px;
            padding: 0px;
        }

        body, button, input, select, textarea {
            font: 12px/16px Verdana, Helvetica, Arial, sans-serif;
        }

        p {
            width: 603px;
            padding-top: 3px;
            overflow: hidden;
        }

        #container {
            min-width: 603px;
            min-height: 767px;
        }
    </style>
    <script charset="utf-8" src="https://map.qq.com/api/js?v=2.exp"></script>
    <script>
        var searchService, markers = [];
        var init = function () {
            var map = new qq.maps.Map(document.getElementById("container"), {
                center: new qq.maps.LatLng(24.465901, 118.118820),
                zoom: 13
            });
            //绑定单击事件添加参数
            qq.maps.event.addListener(map, 'click', function (event) {
                //alert('您点击的位置为: [' + event.latLng.getLat() + ', ' +
                //    event.latLng.getLng() + ']');
                $('#longitude').val(event.latLng.getLng());
                $('#latitude').val(event.latLng.getLat());
            });

            //设置Poi检索服务，用于本地检索、周边检索
            searchService = new qq.maps.SearchService({
                //检索成功的回调函数
                complete: function (results) {
                    //设置回调函数参数
                    var pois = results.detail.pois;
                    var infoWin = new qq.maps.InfoWindow({
                        map: map
                    });
                    var latlngBounds = new qq.maps.LatLngBounds();
                    for (var i = 0, l = pois.length; i < l; i++) {
                        var poi = pois[i];
                        //扩展边界范围，用来包含搜索到的Poi点
                        latlngBounds.extend(poi.latLng);

                        (function (n) {
                            var marker = new qq.maps.Marker({
                                map: map
                            });
                            marker.setPosition(pois[n].latLng);

                            marker.setTitle(i + 1);
                            markers.push(marker);


                            qq.maps.event.addListener(marker, 'click', function () {
                                infoWin.open();
                                infoWin.setContent('<div style="width:280px;height:100px;">' + 'POI的ID为：' +
                                    pois[n].id + '，POI的名称为：' + pois[n].name + '，POI的地址为：' + pois[n].address + '，POI的类型为：' + pois[n].type + '</div>');
                                infoWin.setPosition(pois[n].latLng);
                            });
                        })(i);
                    }
                    //调整地图视野
                    map.fitBounds(latlngBounds);
                },
                //若服务请求失败，则运行以下函数
                error: function () {
                    alert("出错了。");
                }
            });
        }


        //清除地图上的marker
        function clearOverlays(overlays) {
            var overlay;
            while (overlay = overlays.pop()) {
                overlay.setMap(null);
            }
        }
        //设置搜索的范围和关键字等属性
        function searchKeyword() {
            var keyword = document.getElementById("keyword").value;
            var region = document.getElementById("region").value;
            var pageIndex = parseInt(document.getElementById("pageIndex").value);
            var pageCapacity = parseInt(document.getElementById("pageCapacity").value);
            clearOverlays(markers);
            //根据输入的城市设置搜索范围
            searchService.setLocation(region);
            //设置搜索页码
            searchService.setPageIndex(pageIndex);
            //设置每页的结果数
            searchService.setPageCapacity(pageCapacity);
            //根据输入的关键字在搜索范围内检索
            searchService.search(keyword);
            //根据输入的关键字在圆形范围内检索
            //var region = new qq.maps.LatLng(39.916527,116.397128);
            //searchService.searchNearBy(keyword, region , 2000);
            //根据输入的关键字在矩形范围内检索
            //region = new qq.maps.LatLngBounds(new qq.maps.LatLng(39.936273,116.440043),new qq.maps.LatLng(39.896775,116.354212));
            //searchService.searchInBounds(keyword, region);
        }
    </script>
</head>
<body>
    <div class="wrapper wrapper-content animated fadeInRight">
        <form method="post" class="form-horizontal" action="" id="myformdata" enctype="multipart/form-data">
            <div class="row">
                <div class="col-sm-12">
                    <div class="ibox float-e-margins">
                        <div class="ibox-content">
                            <div class="form-group">
                                <input type="hidden" name="id" value="{$v.id}" />
                                <label class="col-sm-5 control-label">{:lang('商户名称')}</label>
                                <div class="col-sm-7">
                                    <input type="text" class="form-control" name="name" id="name" value="{$v.name}" required placeholder="{:lang('输入')}{:lang('商户名称')}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-5 control-label">{:lang('电话')}</label>
                                <div class="col-sm-7">
                                    <input type="text" class="form-control" name="phone" id="phone" value="{$v.phone}" required placeholder="{:lang('输入')}{:lang('电话')}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-5 control-label">{:lang('联系人')}</label>
                                <div class="col-sm-7">
                                    <input type="text" class="form-control" name="contacts" id="contacts" value="{$v.contacts}" required placeholder="{:lang('输入')}{:lang('联系人')}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-5 control-label">{:lang('绑定手机电话')}</label>
                                <div class="col-sm-7">
                                    <input type="text" class="form-control" name="mobile" id="mobile" value="{$v.mobile}" placeholder="{:lang('输入')}{:lang('绑定手机电话')}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-5 control-label">{:lang('佣金比例')}</label>
                                <div class="col-sm-7">
                                    <input type="text" class="form-control" id="brokerage" name="brokerage" value="{$v.brokerage}" placeholder="{:lang('输入')}{:lang('佣金比例')}">
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-5 control-label">{:lang('设置单价')}</label>
                                <div class="col-sm-7">
                                    <input type="text" class="form-control" name="per_price" id="per_price" value="{$v.per_price}" placeholder="{:lang('输入')}{:lang('设置单价')}">
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-5 control-label">{:lang('门店照')}</label>
                                <div class="col-sm-7">
                                    <div class="file-loading">
                                        <input id="uploadfile" name="img_file" type="file" multiple data-overwrite-initial="false" class="file">
                                    </div>
                                </div>
                            </div>
                            <input type="hidden" id="picture" name="picture" value="">

                            <div class="form-group">
                                <label class="col-sm-5 control-label">{:lang('门店地址')}</label>
                                <label>
                                    <select data-placeholder="选择省份......" class="province  form-control" id='province' name="province" style="width:150px;" tabindex="2">
                                        <option value="">{:lang('选择省份')}</option>
                                        {volist name="province" id="vo"}
                                        <option value="{$vo.addr_id}" <?php if(isset($v['province'])){ if($vo['addr_id']==$v['province']){ echo "selected = 'selected'";}} ?>>{$vo.addr_name}</option>
                                        {/volist}
                                    </select>
                                </label><?php foreach($city as $province_id=>$val){  ?>
                                <label>
                                    <select style="<?php echo ($v['province'] == $province_id)?"":"display:none"; ?>" name="city" data-placeholder="选择城市......" class="form-control" id='city_<?php echo $province_id;?>' name="" style="width:150px;" tabindex="2">
                                        <option value="">{:lang('选择城市')}</option><?php foreach($val as $c){ ?>
                                        <option value="{$c.addr_id}" hassubinfo="true" <?php if(isset($v['city'])){ if($c['addr_id']==$v['city']){ echo "selected = 'selected'";}} ?>><?php echo $c['addr_name'] ?></option><?php }?>
                                    </select>
                                </label><?php }?>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-5 control-label">{:lang('详细地址')}</label>
                                <div class="col-sm-7">
                                    <input type="text" class="form-control" id="addr" name="addr" value="{$v.addr}" placeholder="{:lang('输入')}{:lang('详细地址')}">
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-5 control-label">{:lang('地图定位')}</label>
                                <div class="col-sm-7">
                                    <input type="button" class="form-control" data-val="show" id="show_map" style="width:110px;height:35px;" value="{:lang('显示地图')}">
                                    <div id="search_map" style="display:none;">
                                        <input id="keyword" type="textbox" value="酒店">
                                        <input id="region" type="textbox" value="北京">页码:
                                        <input id="pageIndex" type="textbox" value="0" style="width:30px">每页结果数:
                                        <input id="pageCapacity" type="textbox" value="5" style="width:30px">
                                        <input type="button" value="搜索" onclick="searchKeyword()">
                                    </div>
                                </div>
                                <div class="col-sm-7" style="float:right;">
                                    <div id="container" style="display:none">

                                    </div>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-5 control-label">{:lang('经度')}</label>
                                <div class="col-sm-7">
                                    <input type="text" class="form-control" id="longitude" name="longitude" value="{$v.longitude}" placeholder="{:lang('输入')}{:lang('经度')}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-5 control-label">{:lang('纬度')}</label>
                                <div class="col-sm-7">
                                    <input type="text" class="form-control" id="latitude" name="latitude" value="{$v.latitude}" placeholder="{:lang('输入')}{:lang('纬度')}">
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-5 control-label">{:lang('归属代理')}</label>
                                <label>
                                    <select data-placeholder="归属代理......" class="agency  form-control" id='agency' name="agency" style="width:150px;" tabindex="2">
                                        <option value="">{:lang('归属代理')}</option>
                                        {volist name="agent" id="vo"}
                                        <option value="{$vo.id}" hassubinfo="true" <?php if(isset($v['agency'])){ if($vo['id']==$v['agency']){ echo "selected = 'selected'";}} ?>>{$vo.agent_name}</option>
                                        {/volist}
                                    </select>
                                </label><?php foreach($sales as $agent_id=>$val):  ?>
                                <label>
                                    <select style="display:none;" data-placeholder="归属地推......" class="form-control" id='sales_<?php echo $agent_id;?>' name="" style="width:150px;" tabindex="2">
                                        <option value="">{:lang('归属地推')}</option><?php foreach($val as $vo): ?>
                                        <option value="{$vo.id}" hassubinfo="true" <?php if(isset($v['salesman'])){ if($vo['id']==$v['salesman']){ echo "selected = 'selected'";}} ?>>{$vo.agent_name}</option><?php endforeach; ?>
                                    </select>
                                </label><?php endforeach;?>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-sm-12">
                    <div class="form-group">
                        <div class="col-sm-5 col-sm-offset-5">
                            <input type="button" class="btn btn-primary" value="{:lang('提交')}" id="onbtn">
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</body>
<script src="{$Think.config.site.resource_url}js/jquery.min.js?v=2.1.4"></script>
<script src="{$Think.config.site.resource_url}js/bootstrap.min.js?v=3.3.5"></script>
<script src="{$Think.config.site.resource_url}js/fileinput.js" type="text/javascript"></script>
<script src="{$Think.config.site.resource_url}js/zh.js" type="text/javascript"></script>
<script src="{$Think.config.site.resource_url}js/plugins/validate/jquery.validate.min.js"></script>
<script src="{$Think.config.site.resource_url}js/plugins/validate/messages_zh.min.js"></script>
<script>
//初始化fileinput控件（第一次初始化）
initFileInput("uploadfile", '<?php echo \think\Request::instance()->root(); ?>/ausadmin/Agent/file_upload',{$init_image},{$con});


//初始化fileinput控件（第一次初始化）
function initFileInput(ctrlName, uploadUrl,images,con) {
    var control = $('#' + ctrlName);
    control.fileinput({
        language: 'zh', //设置语言
        uploadUrl: uploadUrl, //上传的地址
        allowedFileExtensions : ['jpg', 'png','gif'],//接收的文件后缀
        showCaption: false,//是否显示标题
        showUpload: true, //是否显示上传按钮
        browseClass: "btn btn-primary", //按钮样式
        browseClass: "btn btn-primary btn-lg",
        fileType: "any",
        previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
        overwriteInitial: false,
        initialPreviewAsData: true,
        initialPreview:images,
        initialPreviewConfig:con 
    });
}

$(document).ready(function(){
    //异步图片上传返回结果处理
    $("#uploadfile").on("fileuploaded", function (event,data) {
        $('#picture').val($('#picture').val()+"\n"+data.response.data);
        return true;
    });

	$('#show_map').click(function(){
        val = $(this).attr('data-val');
        if(val == "show"){
            $(this).attr('data-val','hide');
            $('#container').show();
            $('#search_map').show();
            init();
        }else{
            $(this).attr('data-val','show');
            $('#container').hide();
            $('#search_map').hide();
        }
	});


	$('.province').change(function(){
       val = $(this).val();
       $("[id^=city_]").hide();
       $("[id^=city_]").attr("name","");
       $('#city_'+val).attr("name","city");
       $('#city_'+val).show();
	});


    $('.agency').change(function(){
       val = $(this).val();
       $("[id^=sales_]").hide();
       $("[id^=sales_]").attr("name","");
       $('#sales_'+val).attr("name","salesman");
       $('#sales_'+val).show();
	});


	$('#onbtn').click(function(){
        var name = $('#name').val();
        var phone = $('#phone').val();
        if(name==''){
            $('#name').focus();
            return false;
        }
        if(phone==''){
            $('#phone').focus();
            return false;
        }

		//var fomrData = $("#myformdata").serialize();
        var formData = new FormData($( "#myformdata" )[0]);
		var action = 'edit';
		$.ajax({
			type : 'POST',
			url : '<?php echo \think\Request::instance()->root(); ?>/ausadmin/Seller/'+action,
			data: formData,
            async: false,
            cache: false,
            contentType: false,
            processData: false,
			success : function(result) {
                //layer.close(layer1);
                if(0 === result.code) {
                    layer.msg(result.msg, {icon: 1});
                    parent.location.reload();
                }  else  {
                    //删除失败
                    layer.msg(result.msg, {icon: 5});
                }
            },
            error : function(){
                res = false;
                layer.msg("{:lang('服务器错误！请稍后重试')}", {icon: 2});
            }
		})
	});
})
</script>
</html>

